using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Common;
using Microsoft.TeamFoundation.VersionControl.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace ScrumPowerTools.Models
{
    internal class WorkItemCollector
    {
        private readonly IVsTeamExplorer teamExplorer;

        public WorkItemCollector(IVsTeamExplorer teamExplorer)
        {
            this.teamExplorer = teamExplorer;
        }

        internal void CollectItems(int workItemId, IWorkItemCollectorStrategy strategy)
        {
            CollectForWorkItem(workItemId, strategy);
        }

        private void CollectForWorkItem(int selectedItemIds, IWorkItemCollectorStrategy strategy)
        {
            var tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(teamExplorer.GetProjectContext().DomainUri));

            WorkItemStore store = tpc.GetService<WorkItemStore>();
            WorkItem workItem = store.GetWorkItem(selectedItemIds);
            VersionControlServer versionControlServer = tpc.GetService<VersionControlServer>();

            strategy.Collect(workItem, store, versionControlServer);
        }
    }
}